package com.shenhangye.pushlive.codec

import android.opengl.EGLContext
import com.shenhangye.pushlive.gles.EglCore
import com.shenhangye.pushlive.gles.WindowSurface
import java.io.File

class TextureMovieEncoder:Runnable {

    var mInputWindowSurface:WindowSurface?=null;
    var mEglCore:EglCore?=null;

    var mVideoEncoder:VideoEncoderCore?=null

    public class EncoderConfig{
        var mOutputFile:File?=null
        var mWidth=0
        var mHeight=0
        var mBitRate=0;
        var mEglContext:EGLContext?=null

        constructor(
            mOutputFile: File?,
            mHeight: Int,
            mWidth: Int,
            mBitRate: Int,
            mEglContext: EGLContext?
        ) {
            this.mOutputFile = mOutputFile
            this.mHeight = mHeight
            this.mWidth = mWidth
            this.mBitRate = mBitRate
            this.mEglContext = mEglContext
        }

        override fun toString(): String {
            return "EncoderConfig(mOutputFile=$mOutputFile, mWidth=$mWidth, mHeight=$mHeight, mBitRate=$mBitRate, mEglContext=$mEglContext)"
        }
    }

    fun prepareEncoder(sharedContext:EGLContext,
                       width:Int,
                       height:Int,
                       bitRate:Int,
                       outputFile:File){

        mVideoEncoder=VideoEncoderCore(width,height,bitRate,outputFile)

        mEglCore= EglCore(sharedContext,EglCore.FLAG_RECORDABLE)

        mInputWindowSurface= WindowSurface(mEglCore!!,mVideoEncoder?.getInputSurface()!!,true)

        mInputWindowSurface?.makeCurrent()
    }

    private var mFrameNum = 0
    fun handleStartRecording(encoderConfig: EncoderConfig){
        mFrameNum=0;

    }

    override fun run() {

    }
}